package com.lml.jdk8.test03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author Administrator
 * @date 2020/2/26 18:49
 * Description:
 */
public class TestPredicate {

    public static void main(String[] args) {
        List<String> testList = Arrays.asList("1234", "123456", "Predicate");
        List<String> filterString = filterString(testList, s -> s.length() > 5);
        System.out.println(filterString.toString());
    }

    static List<String> filterString(List<String> list, Predicate<String> p) {
        //定义一个新的List集合,放入过滤后的字符串
        List<String> newList = new ArrayList<>();
        for (String str : list) {
            if (p.test(str)) {
                newList.add(str);
            }
        }
        return newList;
    }
}
